package com.learner.exam.controller;

import com.learner.exam.service.ExamService;
import com.learner.pojo.exam.Exam;
import com.learner.pojo.exam.vo.AddExamByBankVo;
import com.learner.pojo.exam.vo.AddExamByQuestionVo;
import com.learner.pojo.exam.vo.ExamQueryVo;
import com.learner.pojo.exam.vo.PageResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @author linweibing
 * @date 2023-03-10 23:04
 * @description: 考试的控制器
 */
@RestController
@RequestMapping("/api/exam")
public class ExamController {

    @Autowired
    private ExamService examService;


    /**
     * 根据信息查询考试的信息
     *
     * @param examQueryVo 参数
     * @return 结果
     */
    @PostMapping("/get")
    public PageResponse<Exam> getExamInfo(@RequestBody ExamQueryVo examQueryVo) {
        return examService.getExamPage(examQueryVo);
    }

    /**
     * 根据考试id查询考试的信息和题目列表
     *
     * @param examId 考试id
     * @return 结果
     */
    @GetMapping("/{id}")
    public AddExamByQuestionVo getExamInfoById(@PathVariable("id") Integer examId) {
        return examService.getExamInfoById(examId);
    }

    /**
     * 查询所有考试
     *
     * @return 结果
     */
    @GetMapping("/list")
    public List<Exam> allExamInfo() {
        return examService.list(null);
    }

    /**
     * 操作考试的信息表(type 1启用 2禁用 3删除)
     *
     * @param type 操作类型
     * @param ids  id列表
     */
    @GetMapping("/operationExam/{type}")
    public void operationExam(@PathVariable("type") Integer type, String ids) {
        examService.operationExam(type, ids);
    }


    /**
     * 根据题库添加考试
     *
     * @param addExamByBankVo 题库实体
     */
    @PostMapping("/addExamByBank")
    public void addExamByBank(@RequestBody @Valid AddExamByBankVo addExamByBankVo) {
        examService.addExamByBank(addExamByBankVo);
    }


    /**
     * 根据题目列表添加考试
     *
     * @param addExamByQuestionVo 题目列表
     */
    @PostMapping("/addExamByQuestionList")
    public void addExamByQuestionList(@RequestBody @Valid AddExamByQuestionVo addExamByQuestionVo) {
        examService.addExamByQuestionList(addExamByQuestionVo);
    }

    /**
     * 修改考试信息
     *
     * @param addExamByQuestionVo 参数
     */
    @PostMapping("/updateExamInfo")
    public void updateExamInfo(@RequestBody AddExamByQuestionVo addExamByQuestionVo) {
        examService.updateExamInfo(addExamByQuestionVo);
    }

    /**
     * 提供每一门考试的通过率数据(echarts绘图)
     *
     * @return 数据
     */
    @GetMapping("/getExamPassRate")
    public List<String> getExamPassRate() {
        return examService.getExamPassRateEchartData();
    }

    /**
     * 提供每一门考试的考试次数(echarts绘图)
     *
     * @return 数据
     */
    @GetMapping("/getExamNumbers")
    public List<String> getExamNumbers() {
        return examService.getExamNumbersEchartData();
    }

}
